home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / INIT - CDEV / INITInstall.a < prev    next >
Encoding:
Text File  |  1991-01-15  |  5.8 KB  |  168 lines  |  [TEXT/MPS ]

  1. ;------------------------------------------------------------------------------
  2. ;
  3. ;    Apple Macintosh Developer Technical Support
  4. ;
  5. ;    Sample Control Panel Device and INIT Combination
  6. ;
  7. ;    Program:    INIT - CDEV
  8. ;    File:        INITInstall - Asm source
  9. ;
  10. ;    Copyright © 1990 Apple Computer, Inc.
  11. ;    All rights reserved.
  12. ;
  13. ;------------------------------------------------------------------------------
  14.  
  15.                 include 'ToolEqu.a'
  16.                 include 'SysEqu.a'
  17.                 include 'QuickEqu.a'
  18.                 include 'Traps.a'
  19.  
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21. ;
  22. ;    These are the IDs for the icons used by ShowINIT. ShowINIT is a really
  23. ;    cool hack by Paul Mercer that displays those icons across the bottom of
  24. ;    your screen when you boot up. You can choose what icon to show up, based
  25. ;    on how the installation went. If the installation went OK, we show the
  26. ;    INIT's icon. Because this is also a CDEV, the Icon resource ID is -4064
  27. ;    (per Inside Mac on Control Panels). If the installation didn't work, we
  28. ;    show a version of the icon with an X through it. The ID for this icon
  29. ;    doesn't have any restrictions on it, so we just use the ID of 128 that
  30. ;    ResEdit gave us.
  31. ;
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33.  
  34. IconID            EQU        -4064
  35. BadIconID        EQU        128
  36.  
  37. SystemTaskTrap    EQU        $A9B4                    ; trap number of routine to patch
  38.  
  39. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  40. ;
  41. ;    MACRO
  42. ;        ChangeTrap    &trap, &type, &newAddress, &oldAddressStore
  43. ;
  44. ;        Macro used to change the trap address and optionally save the old
  45. ;        routine's address. You pass in the trap number of the trap you want
  46. ;        to patch, the type of the trap (newTool or newOS), the address of the
  47. ;        routine to store in the trap table, and a pointer to a memory location
  48. ;        that will hold the old address. If &oldAddressStore is some value other
  49. ;        than NIL, this macro will get the old trap's address and save it there.
  50. ;
  51. ;        NOTE:    This macro translates &newAddress and &oldAddressStore into
  52. ;                their new locations. To do this, it relies on A1 pointing to
  53. ;                the block in the system heap that holds the patch, and for
  54. ;                FirstResByte to be defined.
  55. ;
  56. ;    Input:
  57. ;        A1: address of patch code in system heap
  58. ;
  59. ;    Output:
  60. ;        oldAddressStore: address of old trap routine
  61. ;        D0, A0 are destroyed.
  62. ;
  63. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  64.  
  65.             MACRO
  66.             ChangeTrap    &trap,&type,&newAddress,&oldAddressStore
  67.  
  68.             IF (&oldAddressStore ≠ 'NIL') THEN
  69.  
  70.                 move.w    #&trap,D0
  71.                 _GetTrapAddress ,&type
  72.                 move.l    A0,&oldAddressStore-FirstResByte(A1)
  73.  
  74.             ENDIF
  75.  
  76.                 move.w    #&trap,D0
  77.                 lea        &newAddress-FirstResByte(A1),A0
  78.                 _SetTrapAddress ,&type
  79.  
  80.             ENDM
  81.  
  82.  
  83. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  84. ;
  85. ;    Generic install routine. This is the code that gets executed when INIT 31
  86. ;    calls our INIT. The first thing we do is check to see if any of the scare
  87. ;    buttons are being pressed. If the user is holding down the shift key or
  88. ;    mouse button, then don't install, and show the unhappy icon. If not, then
  89. ;    find out how large our resident code will be, and get a non-relocatable
  90. ;    block of memory in the heap that size by calling _NewPtr. We determine the
  91. ;    size of our resident code by getting the size of our INIT, and subtracting
  92. ;    everything that comes before "FirstResByte".
  93. ;
  94. ;    If we can't get a block of memory that size, we blow out with an unhappy
  95. ;    icon. Otherwise, we call BlockMove to move our resident code into the
  96. ;    System heap. Then we call a C routine that does some more installation
  97. ;    stuff. In our case, we want to make sure that we can make PPCToolbox
  98. ;    calls. If there are any errors, we de-allocate our memory and exit with
  99. ;    an unhappy icon. If everything went OK in the C world, we patch in our
  100. ;    trap routine, and display a happy icon.
  101. ;
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103.  
  104. INITInstall        PROC    EXPORT
  105.                 IMPORT    SHOWINIT
  106.                 IMPORT    a_SystemTask:CODE
  107.                 IMPORT    c_Install:CODE
  108.                 IMPORT    oldSystemTask:DATA
  109.  
  110. FirstResByte    EQU        a_SystemTask            ; first resident byte
  111. ShiftKey        EQU        56                        ; key code for Shift key
  112.  
  113.                 tst.b    MBState                    ; don't install if mouse button is down
  114.                 bpl.s    NoInstall                ;
  115.  
  116.                 btst    #(ShiftKey//8),KeyMap+(ShiftKey/8)    ; or if shift key is down
  117.                 bne.s    NoInstall                ;
  118.  
  119.                 lea        INITInstall,A0            ; get location of the INIT
  120.                 _RecoverHandle                    ; get our handle
  121.                 _GetHandleSize                    ; find out how large we are in D0
  122.                 lea        FirstResByte,A0            ; first byte of resident code
  123.                 lea        INITInstall,A1            ; first byte of header
  124.                 sub.l    A1,A0                    ; size of header to be discarded
  125.                 sub.l    A0,D0                    ; remove header from INIT to get resident size
  126.                 move.l    D0,D1                    ; save size later for BlockMove
  127.  
  128.                 _NewPtr ,sys                    ; make the resident block in System heap
  129.                 tst.w    d0                        ; check for getting an error
  130.                 bne.s    NoInstall                ; got one, blow out
  131.                 move.l    A0,A1                    ; save new location for _BlockMove
  132.  
  133.                 lea        FirstResByte,A0            ; set A0 to source
  134.                 move.l    D1,D0                    ; set D0 to size
  135.                 _BlockMove
  136.  
  137.                 move.l    A1,-(sp)                ; save A1 for ChangeTrap call
  138.                 lea        c_Install-FirstResByte(A1),A0    ; set to call C installation code in its new location
  139.                 jsr        (A0)                    ; call it
  140.                 move.l    (sp)+,A1                ; restore A1 for ChangeTrap call
  141.                 tst.w    D0                        ; any errors?
  142.                 bne.s    RemoveNoInstall            ; yes, so de-allocate our memory
  143.  
  144.                 ;
  145.                 ; note: this macro destroys D0, A0
  146.                 ;        and relies on A1 being set.
  147.                 ;
  148.  
  149.                 ChangeTrap    SystemTaskTrap, newTool, a_SystemTask, oldSystemTask
  150.  
  151. ExitInit
  152.                 move.w    #IconID,-(sp)            ; ICN# ID of happy icon
  153.                 bra.s    ShowTheIcon                ;
  154.  
  155. RemoveNoInstall
  156.                 move.l    A1,A0                    ; dispose of our memory in case of error
  157.                 _DisposPtr
  158. NoInstall
  159.                 move.w    #BadIconID,-(sp)        ; ICN# ID of unhappy icon
  160. ShowTheIcon
  161.                 move.w    #-1,-(sp)                ; use default moveX
  162.                 bsr        SHOWINIT                ; draw the icon
  163.                 rts                                ; return to INIT 31
  164.  
  165.                 ENDP
  166.                 END
  167.  
  168.